//
//  ShopCartProductCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/23.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "ShopCartProductCell.h"

@interface ShopCartProductCell ()<UITextFieldDelegate>



@end

@implementation ShopCartProductCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.countTF.delegate = self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    WEAKSELF
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [weakSelf.mainImageView pp_clipCorners:UIRectCornerAllCorners radius:3];
    });
    
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    
    if (self.textFieldShouldEndEditingBlock) {
        self.textFieldShouldEndEditingBlock(textField);
    }
    return YES;
}

- (void)fillCellWithModel:(CommonShopCartModel *)model {
    
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.sellerGoodsSpecs.specImage] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.mainTitleLab.text = model.sellerGoodsModel.goodsName;
    
    self.countTF.text = [NSString stringWithFormat:@"%ld",model.goodsNum];
    self.skuLab.text =[NSString stringWithFormat:@"规格：%@",model.sellerGoodsSpecs.specName] ;
    
    self.priceLab.text =[NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.sellerGoodsSpecs.specPrice]];
    
    [self.selBtn setImage:[UIImage imageNamed:model.isSel?@"common_sel":@"common_nor"] forState:UIControlStateNormal];
}

- (IBAction)selectItemAction:(id)sender {
    if (self.ShopCartProductCellBlock) {
        self.ShopCartProductCellBlock(ShopCartProductCellType_sel);
    }
}


- (IBAction)addAction:(id)sender {
    if (self.ShopCartProductCellBlock) {
        self.ShopCartProductCellBlock(ShopCartProductCellType_add);
    }
}

- (IBAction)cutAction:(id)sender {
    if (self.ShopCartProductCellBlock) {
        self.ShopCartProductCellBlock(ShopCartProductCellType_cut);
    }
}


@end
